<template>
  <ai-bubble type="typing" :position="position">
    <view class="ai-typing" aria-busy="true">
      <view class="ai-typing-dot"></view>
      <view class="ai-typing-dot"></view>
      <view class="ai-typing-dot"></view>
    </view>
  </ai-bubble>
</template>

<script>
  export default {
    name: "ai-typing",
    props: {
      position: String
    },
    data() {
      return {
      };
    }
  }
</script>

<style lang="scss">
  @import "@/styles/_var.scss";

  .ai-typing {
    display: flex;
    align-items: center;
    height: 22.5px;
    transition: opacity 0.1s;
  }

  $frame-time: 0.18s;

  .ai-typing-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 6px;
    border-radius: 50%;
    animation: typing-dot ($frame-time * 7) linear infinite;
    background: var(--brand-2);

    &:nth-child(1) {
      margin: 0;
    }

    &:nth-child(2) {
      animation-delay: $frame-time;
    }

    &:nth-child(3) {
      animation-delay: $frame-time * 2;
    }
  }

  @keyframes typing-dot {
    0% {
      transform: scale(1);
    }

    16.67% {
      transform: scale(0);
    }

    33.33% {
      transform: scale(0);
    }

    50% {
      transform: scale(0);
    }

    66.67% {
      transform: scale(1);
    }

    83.33% {
      transform: scale(1);
    }

    100% {
      transform: scale(1);
    }
  }
</style>